﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using CustomAuthorizationDemo.Authorization;
using CustomAuthorizationDemo.DI;
using CustomAuthorizationDemo.Security.Session;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace CustomAuthorizationDemo.Controllers
{
    [AuthorizationFilter]
    [Route("api/[controller]")]
    [ApiController]
    public class TestController : ControllerBase
    {
        [Injection]
        public IClaimsSession Session { get; set; }

        [HttpGet]
        [Route("[action]")]
        public IActionResult CurrentUser() => Ok(Session?.UserName);

        [ApiAuthorize]
        [HttpGet("{id}")]
        public IActionResult Get(int id)=> Ok(id);

        [ApiAuthorize(PermissionNames.TestAdd)]
        [HttpPost]
        [Route("[action]")]
        public IActionResult Create()=> Ok();

        [ApiAuthorize(PermissionNames.TestEdit, RequireAllPermissions = false)]
        [HttpPost]
        [Route("[action]")]
        public IActionResult Update()=> Ok();

        [ApiAuthorize(PermissionNames.TestAdd, PermissionNames.TestEdit, RequireAllPermissions = false)]
        [HttpPost]
        [Route("[action]")]
        public IActionResult Patch() => Ok();

        [ApiAuthorize(PermissionNames.TestDelete)]
        [HttpDelete("{id}")]
        public IActionResult Delete(int id) => Ok();

    }
}